#include <bits/stdc++.h>
using namespace std;
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
using ll = long long;
void solve()
{
    string p, s;
    cin >> p >> s;
    ll l = 0, r = 0;
    while (l < p.size() && r < s.size())
    {
        if (p[l] != s[r])
        {
            cout << "NO\n";
            return;
        }
        ll cnt_l = 0, cnt_r = 0;
        char ch_l = p[l], ch_r = s[r];
        while (l < p.size() && p[l] == ch_l)
        {
            cnt_l++;
            l++;
        }
        while (r < s.size() && s[r] == ch_r)
        {
            cnt_r++;
            r++;
        }
        if (cnt_l > cnt_r)
        {
            no;
            return;
        }
        if (cnt_l * 2 < cnt_r)
        {
            no;
            return;
        }
    }
    if (l == p.size() && r == s.size())
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

}
int main()
{
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}
